<!-- 需求 -->
<template>
	<view>
		<u-empty v-if="!dataList['length']" iconSize="240" textSize="40" class="isempty" marginTop="200"></u-empty>
		<template v-else>
			<view id="need">
				<needCard v-for="item in dataList" :key="item.id" :data="item"></needCard>
<!-- 				<view class="need-card" v-for="(item, index) in need_card_list" :key="index">
					<view @click="getneedicardinfo(item.demandUuid)">
					</view>
				</view> -->
			</view>
			<u-back-top :scroll-top="scrollTop" mode="square" tips="顶部"></u-back-top>
		</template>
	</view>
</template>

<script>
	import {getDemandPageByEs} from "apis/farmer/need.js"
	import needCard from "./needCard.vue"
	export default {
		components:{needCard},
		data(){
			return {
				dataList: [],
				//回到顶部
				scrollTop: 0,
				// 分页
				pageNo: 1,
				pageSize: 20,
			}
		},
		methods:{
			async loadData(){
				const {code,msg,data} = await getDemandPageByEs(this.pageNo,this.pageSize)
				if (code !== 200) return this.$errorMsg(msg)
				for (let item of data["list"]) {
					this.dataList.push(item)
				}
				if(data.lenght >= this.pageSize){
					this.pageNo++
				}
			},
			init(){
				this.dataList = []
				this.pageNo = 1
				this.pageSize = 20
				this.scrollTop = 0
				this.loadData()
			}
			
		},
		onLoad(){
			this.init()
		},
		onReachBottom() { //到达底部
			this.loadData();
		},
		onPullDownRefresh() {
			//监听下拉刷新动作的执行方法，每次手动下拉刷新都会执行一次
			this.init()
			setTimeout(function() {
				uni.stopPullDownRefresh(); //停止下拉刷新动画
			}, 1000);
		},
		onPageScroll(e) { //生命周期函数
			this.scrollTop = e.scrollTop;
		}
	}
</script>

<style>
	@import url("need.css");
</style>
